﻿' *
' * RM2 Character Generator
' * Copyright (C) 2009 James Culshaw
' * 
' * This program is free software; you can redistribute it and/or modify it under the terms of 
' * the GNU General Public License as published by the Free Software Foundation; either version 2 
' * of the License, or (at your option) any later version.
' * 
' * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
' * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
' * See the GNU General Public License for more details.
' * 
' * You should have received a copy of the GNU General Public License along with this program; 
' * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
' *

Imports System.Collections.Generic
Imports System.Xml
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports RMCharGen.Data

'''<summary>
'''This is a test class for LoaderTest and is intended
'''to contain all LoaderTest Unit Tests
'''</summary>
<TestClass()> _
Public Class LoaderTest


    Private testContextInstance As TestContext

    '''<summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return testContextInstance
        End Get
        Set(ByVal value As TestContext)
            testContextInstance = Value
        End Set
    End Property

#Region "Additional test attributes"
    '
    'You can use the following additional attributes as you write your tests:
    '
    'Use ClassInitialize to run code before running the first test in the class
    '<ClassInitialize()>  _
    'Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
    'End Sub
    '
    'Use ClassCleanup to run code after all tests in a class have run
    '<ClassCleanup()>  _
    'Public Shared Sub MyClassCleanup()
    'End Sub
    '
    'Use TestInitialize to run code before running each test
    '<TestInitialize()>  _
    'Public Sub MyTestInitialize()
    'End Sub
    '
    'Use TestCleanup to run code after each test has run
    '<TestCleanup()>  _
    'Public Sub MyTestCleanup()
    'End Sub
    '
#End Region


    '''<summary>
    '''A test for LoadSkills
    '''</summary>
    <TestMethod(), _
     DeploymentItem("RMCharGen.exe")> _
    Public Sub LoadSkillsTest()
        Dim expected As Dictionary(Of String, Skill_Accessor) = Nothing ' TODO: Initialize to an appropriate value
        Dim actual As Dictionary(Of String, Skill_Accessor)
        actual = Loader_Accessor.LoadSkills
        Assert.AreEqual(expected, actual)
        Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for LoadSkill
    '''</summary>
    <TestMethod(), _
     DeploymentItem("RMCharGen.exe")> _
    Public Sub LoadSkillTest()

        Dim xmlDOM As New XmlDocument()
        Dim skillElement As XmlElement = xmlDOM.CreateElement("Skill")
        skillElement.SetAttribute("name", "Name")
        skillElement.SetAttribute("statOne", "AG")
        skillElement.SetAttribute("statTwo", "Pr")
        skillElement.SetAttribute("statThree", "Qu")
        skillElement.SetAttribute("typeOne", "Type One")
        skillElement.SetAttribute("typeTwo", "Type Two")
        skillElement.SetAttribute("primary", "Yes")

        Dim actual As Skill_Accessor
        actual = Loader_Accessor.LoadSkill(skillElement)
        Assert.AreEqual("Name", actual.Name)
        Assert.AreEqual("AG", actual.StatOne)
        Assert.AreEqual("Pr", actual.StatTwo)
        Assert.AreEqual("Qu", actual.StatThree)
        Assert.AreEqual("Type One", actual.TypeOne)
        Assert.AreEqual("Type Two", actual.TypeTwo)
        Assert.IsTrue(actual.IsPrimary)

    End Sub

    '''<summary>
    '''A test for LoadSkill
    '''</summary>
    <TestMethod(), _
     DeploymentItem("RMCharGen.exe")> _
    Public Sub LoadSkillTest2()

        Dim xmlDOM As New XmlDocument()
        Dim skillElement As XmlElement = xmlDOM.CreateElement("Skill")
        skillElement.SetAttribute("name", "Name")

        Dim actual As Skill_Accessor
        actual = Loader_Accessor.LoadSkill(skillElement)
        Assert.AreEqual("Name", actual.Name)
        Assert.AreEqual(String.Empty, actual.StatOne)
        Assert.AreEqual(String.Empty, actual.StatTwo)
        Assert.AreEqual(String.Empty, actual.StatThree)
        Assert.AreEqual(String.Empty, actual.TypeOne)
        Assert.AreEqual(String.Empty, actual.TypeTwo)
        Assert.IsFalse(actual.IsPrimary)

    End Sub

    '''<summary>
    '''A test for LoadSkill
    '''</summary>
    <TestMethod(), _
     ExpectedException(GetType(InvalidStatTypeException)), _
     DeploymentItem("RMCharGen.exe")> _
    Public Sub LoadSkillFailTest()

        Dim xmlDOM As New XmlDocument()
        Dim skillElement As XmlElement = xmlDOM.CreateElement("Skill")
        skillElement.SetAttribute("name", "Name")
        skillElement.SetAttribute("statOne", "PR")
        Dim actual As Skill_Accessor
        actual = Loader_Accessor.LoadSkill(skillElement)

    End Sub

End Class
